package cn.com.generaldata.os.service.factory;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;

import cn.com.generaldata.os.common.GlobalSetting;
import cn.com.generaldata.os.service.common.AbstractPmService;
import cn.com.generaldata.os.util.SpringContextHolder;

/**
 * PM的工厂bean，
 * 
 */
@Component
public class PmFactoryBean implements FactoryBean<AbstractPmService> {

	@Override
	public AbstractPmService getObject() throws Exception {
		GlobalSetting setting = (GlobalSetting) SpringContextHolder.getBean("globalSetting");
		if (setting.getProjectRunMode().equals("LAN")) {
			return (AbstractPmService) SpringContextHolder.getBean("pmServiceForLan");
		} else {
			return (AbstractPmService) SpringContextHolder.getBean("pmServiceForWeb");
		}
	}

	@Override
	public Class<?> getObjectType() {
		return AbstractPmService.class;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

}
